package org.stvd.entities.admin;

import java.util.Date;

import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.Id;
import javax.persistence.Table;
import javax.persistence.Transient;

import org.hibernate.validator.constraints.NotEmpty;
import org.springframework.format.annotation.DateTimeFormat;
import org.stvd.core.annotation.serializer.DateSerializer;
import org.stvd.core.annotation.serializer.DateTimeSerializer;
import org.stvd.core.util.DateUtil;
import org.stvd.entities.base.BaseEntity;

import com.fasterxml.jackson.annotation.JsonIgnore;
import com.fasterxml.jackson.databind.annotation.JsonSerialize;

/**
 * 用户基本信息-实体类
 * @author houzx
 */
@Entity
@Table(name="user_base")
public class UserBase extends BaseEntity{
    
    private static final long serialVersionUID = 3205348626676688839L;
    /**
     * 用户ID
     */
    @Id
    @Column(name="user_id",nullable=false)
    private String userId = "";
    
    /**
     * 用户昵称
     */
    @Column(name="nick_name",nullable=false)
    @NotEmpty(message="用户昵称不能为空！")
    private String nickName = "";
    
    /**
     * 出生日期
     */
    @Column(name="birthday")
    @DateTimeFormat(pattern = "yyyy-MM-dd")
    @JsonSerialize(using = DateSerializer.class)
    private Date birthday = null;
    
    /**
     * 性别
     */
    @Column(name="sex")
    private String sex = "";
    
    /**
     * 头像
     */
    @Column(name="avatar")
    @JsonIgnore
    private byte[] avatar = null;
    
    /**
     * 省
     */
    @Column(name="province")
    private String province = "";

    /**
     * 市
     */
    @Column(name="city")
    private String city = "";
    
    /**
     * 区
     */
    @Column(name="region")
    private String region = "";
    
    /**
     * 区域代码
     */
    @Column(name="area_no")
    private String areaNo = "";
    
    /**
     * 用户签名
     */
    @Column(name="signature")
    private String signature = "";
    
    /**
     * 更新用户
     */
    @Column(name="modify_user")
    @JsonIgnore
    private String modifyUser = "";
    
    /**
     * 更新时间
     */
    @Column(name="modify_time")
    @DateTimeFormat(pattern="yyyy-MM-dd HH:mm:ss")
    @JsonSerialize(using = DateTimeSerializer.class)
    private Date modifyTime = null;
    
    /**
     * 认证类型{-1：未认证；1：个人；2：专家；3：团队；4：企业；}
     */
    @Column(name="auth_type")
    private String authType = "-1";
    
    /**
     * 认证状态{-1：审核未通过；0：等待审核；1：审核通过；}
     */
    @Column(name="auth_status")
    private String authStatus= "";
    
    /**
     * 企业ID
     */
    @Column(name="comp_id")
    private String compId = "-1";
    
    /**
     * 团队ID 
     */
    @Column(name="team_id")
    private String teamId = "-1";
    
    @Transient
    @JsonIgnore
    private String provinceNo = "000000" ;   
    
    @Transient
    @JsonIgnore
    private String cityNo = "000000" ;   
    
    @Transient
    @JsonIgnore
    private String regionNo = "000000" ; 
    
    @Transient
    private String avatarStr;
    
    public String getUserId() {
		return userId;
	}

	public void setUserId(String userId) {
		this.userId = userId;
	}

	public String getNickName() {
		return nickName;
	}

	public void setNickName(String nickName) {
		this.nickName = nickName;
	}

	public Date getBirthday() {
		return birthday;
	}

	public void setBirthday(Date birthday) {
		this.birthday = birthday;
	}

	public String getSex() {
		return sex;
	}

	public void setSex(String sex) {
		this.sex = sex;
	}

	public byte[] getAvatar() {
		return avatar;
	}

	public void setAvatar(byte[] avatar) {
		this.avatar = avatar;
	}

	public String getProvince() {
		return province;
	}

	public void setProvince(String province) {
		this.province = province;
	}

	public String getCity() {
		return city;
	}

	public void setCity(String city) {
		this.city = city;
	}

	public String getRegion() {
		return region;
	}

	public void setRegion(String region) {
		this.region = region;
	}

	public String getAreaNo() {
		return areaNo;
	}

	public void setAreaNo(String areaNo) {
		this.areaNo = areaNo;
	}

	public String getSignature() {
		return signature;
	}

	public void setSignature(String signature) {
		this.signature = signature;
	}

	public Date getModifyTime() {
		return modifyTime;
	}

	public void setModifyTime(Date modifyTime) {
		this.modifyTime = modifyTime;
	}
	
	public String getModifyUser() {
		return modifyUser;
	}

	public void setModifyUser(String modifyUser) {
		this.modifyUser = modifyUser;
	}
	

	public String getAuthType() {
		return (authType != null && !authType.equals("")) ? authType : "-1";
	}

	public void setAuthType(String authType) {
		this.authType = authType;
	}
	
	public String getAuthStatus() {
		return authStatus;
	}

	public void setAuthStatus(String authStatus) {
		this.authStatus = authStatus;
	}

	public String getCompId() {
        return (compId != null && !compId.equals("")) ? compId:"-1";
    }
    public void setCompId(String compId) {
        this.compId = compId;
    }
    
    public String getTeamId() {
        return  (teamId != null && !teamId.equals(""))?teamId:"-1";
    }
    public void setTeamId(String teamId) {
        this.teamId = teamId;
    }
	
	public String getProvinceNo() {
		return provinceNo;
	}

	public void setProvinceNo(String provinceNo) {
		this.provinceNo = provinceNo;
	}

	public String getCityNo() {
		return cityNo;
	}

	public void setCityNo(String cityNo) {
		this.cityNo = cityNo;
	}

	public String getRegionNo() {
		return regionNo;
	}

	public void setRegionNo(String regionNo) {
		this.regionNo = regionNo;
	}

    public String getAvatarStr() {
        if(avatar != null){
            avatarStr = new String(avatar);
        } 
        return avatarStr ;
    }
    public void setAvatarStr(String avatarStr) {
        this.avatarStr = avatarStr;
    }
    
    @Transient
    public int getAge() { 
        try {
            return DateUtil.getAge(birthday);
        } catch (Exception e) {
            return 0;
        }
    }
}